import { Frame } from '@/frame';
import { Easing, Tween } from '@/lib/tween';

export default class FrameCommon {
    static bounce(frame: Frame, duration: number, scale: number) {
        let prop = frame.props;
        let srcObj = { s: prop.scale };
        let toObj = {
            s: scale,
        };
        let tween1 = new Tween({ ...srcObj })
            .to(toObj, duration * 0.33)
            .easing(Easing.Quadratic.Out)
            .onUpdate((temp) => {
                DzFrameSetScale(frame.current, temp.s);
            });

        let tween2 = new Tween(toObj)
            .to(srcObj, duration * 0.66)
            .easing(Easing.Quadratic.In)
            .onUpdate((temp) => {
                DzFrameSetScale(frame.current, temp.s);
            });
        tween1.chain(tween2);
        DzFrameClearAllPoints(frame.current);
        tween1.start();
    }
    static textBounce(frame: Frame, duration: number, scale: number) {
        let prop = frame.props;
        let srcObj = { s: prop.font.height };
        let toObj = {
            s: prop.font.height * scale,
        };
        let tween1 = new Tween({ ...srcObj })
            .to(toObj, duration * 0.33)
            .easing(Easing.Quadratic.Out)
            .onUpdate((temp) => {
                DzFrameSetScale(frame.current, temp.s);
            });

        let tween2 = new Tween(toObj)
            .to(srcObj, duration * 0.66)
            .easing(Easing.Quadratic.In)
            .onUpdate((temp) => {
                DzFrameSetScale(frame.current, temp.s);
            });
        tween1.chain(tween2);
        tween1.start();
    }
}
